package cn.tedu.ivos.vehicle.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/vehicle/")
public class VehicleController {
    @Autowired
    VehicleService vehicleService;
    @GetMapping("select")
    public JsonResult selectVehicle(VehicleQuery vehicleQuery){
        log.debug("查询信息"+vehicleQuery);
        List<VehicleVO> list= vehicleService.selectVehicle(vehicleQuery);
        log.debug("查询结果"+list);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult addVehicle(VehicleSaveParam vesselSaveParam){
        log.debug("添加信息"+vesselSaveParam);
        vehicleService.addVehicle(vesselSaveParam);
        return JsonResult.ok();
    }
    @PostMapping("delete/{id}")
    public JsonResult deleteVehicle(@PathVariable Long id){
        log.debug("删除信息"+id);
        vehicleService.deleteVehicleById(id);
        return JsonResult.ok();
    }
    @PostMapping("unbind/{vehicleId}")
    public JsonResult unbindVehicle(@PathVariable Long vehicleId){
        log.debug("解绑信息"+vehicleId);
        vehicleService.unbindVehicle(vehicleId);
        return JsonResult.ok();
    }
    @PostMapping("bind/{geofenceId}/{vehicleId}")
    public JsonResult editVehicle(@PathVariable Long geofenceId,@PathVariable Long vehicleId){
        log.debug("绑定信息"+geofenceId+vehicleId);
        vehicleService.bindVehicle(geofenceId,vehicleId);
        return JsonResult.ok();
    }
}
